package com.eva.learn.other.genericsTest;

import java.util.*;

/**
 * Created by evain on 15/11/7.
 */
public class MainTest {
	public static void main(String[] args) {
		TestMethod testMethod = new TestMethod();
		testMethod.add(new ModuleChild1());
		testMethod.add(new ModuleChild1());
		testMethod.add(new ModuleChild2());
		System.out.println(testMethod.toString());
		List<Module> list = new ArrayList<>();

	}
}

class TestMethod<T extends Module> {
	private Map<Class, List<T>> moLists;

	public TestMethod() {
		this.moLists = new HashMap<>();
	}

	public void add(T module) {
		if (moLists.containsKey(module.getClass())) {
			moLists.get(module.getClass()).add(module);
		} else {
			List<T> moduleList = new ArrayList<>();
			moduleList.add(module);
			moLists.put(module.getClass(), moduleList);
		}
	}

	@Override public String toString() {
		StringBuilder stringBuilder = new StringBuilder();
		Iterator iterator = moLists.entrySet().iterator();
		while (iterator.hasNext()) {
			Map.Entry<Class, List<T>> entrySet = (Map.Entry<Class, List<T>>)iterator.next();
			T.Test1();
			stringBuilder.append(entrySet);
		}
		return stringBuilder.toString()+moLists.size();
	}
}

